package com.cetc.baidumaptest;

/**
 * Created by Young on 2017/1/12.
 * 地图可被点击
 * 百度官方API有点击监听方法
 * 方法内有回调方法返回地理位置坐标(百度坐标)
 */
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.DotOptions;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
public class ClickListenerActivity extends AppCompatActivity {
    MapView mMapView = null;
    TextView textViewPoint1= null;
    BaiduMap mBaiduMap = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_click_listener);
        mMapView = (MapView)findViewById(R.id.mapView);
        textViewPoint1 = (TextView)findViewById(R.id.txt_point_1);
        mBaiduMap = mMapView.getMap();
        mBaiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
            public void onMapClick(LatLng point) {
                //在此处理点击事件
                OverlayOptions ooDot = new DotOptions().center(point).radius(10)
                        .color(0xFF00CD00);
                mBaiduMap.addOverlay(ooDot);
                textViewPoint1.setText("纬度"+point.latitude+" 经度"+point.longitude);
            }
            public boolean onMapPoiClick(MapPoi poi) {
                //在此处理底图标注点击事件
                return false;
            }
        });
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        mMapView.onDestroy();
    }
    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        mMapView.onResume();
    }
    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        mMapView.onPause();
    }
}

